import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import _createSuper from "@babel/runtime/helpers/esm/createSuper";

/**
 * 监听 access_token 变化 来判断是否需要 刷新页面
 */
import React from 'react';
import { getAccessToken, getRefreshToken } from "../../../utils/utils";

var DefaultListenAccessToken = /*#__PURE__*/function (_React$Component) {
  _inherits(DefaultListenAccessToken, _React$Component);

  var _super = _createSuper(DefaultListenAccessToken);

  function DefaultListenAccessToken() {
    _classCallCheck(this, DefaultListenAccessToken);

    return _super.apply(this, arguments);
  }

  _createClass(DefaultListenAccessToken, [{
    key: "componentDidMount",
    value: function componentDidMount() {
      // eslint-disable-next-line
      window.accessToken = window.accessToken || getAccessToken('access_token');
      window.refreshToken = window.refreshToken || getRefreshToken('refresh_token');
      this.refreshTimer = setInterval(function () {
        var accessToken = getAccessToken('access_token'); // const refreshToken = getRefreshToken('refresh_token');

        var windowToken = window.accessToken; // const windowRefreshToken = window.refreshToken;

        if (accessToken && windowToken && windowToken !== accessToken) {
          window.location.reload();
        }
      }, 3000);
    }
  }, {
    key: "componentWillUnmount",
    value: function componentWillUnmount() {
      clearInterval(this.refreshTimer);
    }
  }, {
    key: "render",
    value: function render() {
      return null;
    }
  }]);

  return DefaultListenAccessToken;
}(React.Component);

export default DefaultListenAccessToken;